//
//  GameManager.m
//  MobileGameLiving2
//
//  Created by reflection on 15/9/2.
//  Copyright (c) 2015年 李旭东. All rights reserved.
//

#import "GameManager.h"

static NSArray *_videos = nil;

static FRPGame *_playingGame = nil;

@implementation GameManager

+ (FRPGame *)playingGame{
    return _playingGame;
}

+ (void)setPlayingGame:(FRPGame *)playingGame{
    if (!playingGame || ![_videos containsObject:playingGame]) {
        return;
    }
    _playingGame = playingGame;
}

+ (NSArray *)videos{
    if (!_videos) {
        _videos = [self videosFromPlist:@"Game.plist"];
    }
    return _videos;
}

+ (NSArray *)videosFromPlist:(NSString *)plist{
    NSURL *url = [[NSBundle mainBundle]URLForResource:plist withExtension:nil];
    NSArray *objs = [NSArray arrayWithContentsOfURL:url];
    NSMutableArray *games = [[NSMutableArray alloc]init];
    for (NSArray *dict in objs) {
        for (NSDictionary *dictInside in dict) {
            FRPGame *game = [[FRPGame alloc]init];
            [game setValuesForKeysWithDictionary:dictInside];
            [games addObject:game];
        }
    }
    return [games copy];
}


@end
